package com.itlong.cloud.miniprogram.service.impl;

import com.alibaba.fastjson.JSON;
import com.itlong.cloud.POJO.PO.AppUserInfoPO;
import com.itlong.cloud.POJO.PO.WeChatUserOpenIdInfoPO;
import com.itlong.cloud.POJO.VO.app.AppUserCacheVO;
import com.itlong.cloud.POJO.VO.app.AppUserOwnProjectVO;
import com.itlong.cloud.PlatformConstants;
import com.itlong.cloud.app.dao.IAppRegisterDao;
import com.itlong.cloud.app.service.IAppRegisterService;
import com.itlong.cloud.constants.RedisConstant;
import com.itlong.cloud.enumerate.DataStatusEnum;
import com.itlong.cloud.enumerate.SystemTypeEnum;
import com.itlong.cloud.enumerate.ecode.AppErrorCodeEnum;
import com.itlong.cloud.enumerate.ecode_en.AppErrorCodeEnumEN;
import com.itlong.cloud.miniprogram.service.IMiniProgramLoginService;
import com.itlong.cloud.rabbitmq.config.MessageSender;
import com.itlong.cloud.service.RedisService;
import com.itlong.cloud.thrown.DataAccessException;
import com.itlong.cloud.utils.data.handler.SqlUtil;
import com.itlong.cloud.utils.date.DateUtil;
import com.itlong.cloud.utils.encrypt.UserTokenUtil;
import com.itlong.cloud.utils.random.LogicIdUtil;
import com.itlong.cloud.utils.words.StringHandlerUtil;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.data.redis.RedisConnectionFailureException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;

/**
 * <desc>
 *      微信小程序的登录版块实现类.
 * </desc>
 *
 * @createDate 2018/11/24
 */
@Service
@RefreshScope
public class MiniProgramLoginServiceImpl implements IMiniProgramLoginService{

    private static final Logger LOG = LoggerFactory.getLogger(MiniProgramLoginServiceImpl.class);

    @Autowired
    IAppRegisterDao iAppRegisterDao;

    @Value("${" + PlatformConstants.MINI_PROGRAM_USER_TOKEN_KEY + "}")
    public String MINI_PROGRAM_USER_TOKEN_KEY;

    @Autowired
    private RedisService<AppUserCacheVO> redisService;

    @Autowired
    IAppRegisterService iAppRegisterService;

    //消息队列
    @Autowired
    private MessageSender messageSender;

    /**
     * <desc>
     *      根据手机号进行注册或登录
     * </desc>
     * @param phoneNo  手机号
     * @return
     * @author Juguang.S
     * @createDate 2018/11/24
     */
    @Override
    @Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRED)
    public AppUserCacheVO login(String phoneNo,String openId,String unionId) throws Exception {
        AppUserInfoPO userInfoPO = iAppRegisterDao.getUserByPhoneNo(phoneNo);
        WeChatUserOpenIdInfoPO openIdinfoPO = null;
        if(StringUtils.isNotEmpty(unionId) && !unionId.equals("null")){
            openIdinfoPO = iAppRegisterDao.getUserOpenIdInfoByPhoneNo(unionId);
        }
        AppUserCacheVO appUserCacheVO = new AppUserCacheVO();
        //如果为空则是该手机号在APP未注册过，则需将该手机号保存至app-user-info表中
        String userId = "";
        String token = "";
        if(userInfoPO == null){
            userId = LogicIdUtil.userBusinessId();
            token = UserTokenUtil.tokenEncrypt(userId,MINI_PROGRAM_USER_TOKEN_KEY, SystemTypeEnum.MINI_PROGRAM.getType());
            AppUserInfoPO appUserInfoPO = new AppUserInfoPO();
            appUserInfoPO.setUserId(userId);
            appUserInfoPO.setMiniToken(token);
            appUserInfoPO.setPhoneNum(phoneNo);
            appUserInfoPO.setStatus(DataStatusEnum.NORMAL.getType());
            appUserInfoPO.setCreateTime(new Date());
            appUserInfoPO.setUpdateTime(new Date());
            appUserInfoPO.setIsOnline(1);
            iAppRegisterDao.save(SqlUtil.durableData(appUserInfoPO,PlatformConstants.TABLE_SAVE));
        }else{
            userId = userInfoPO.getUserId();
            token = UserTokenUtil.tokenEncrypt(userId,MINI_PROGRAM_USER_TOKEN_KEY, SystemTypeEnum.MINI_PROGRAM.getType());
            appUserCacheVO.setNickName(userInfoPO.getNickName());
            appUserCacheVO.setPhotoUrl(userInfoPO.getIcon());
            appUserCacheVO.setUserName(userInfoPO.getRealName());
        }
        //当前用户没有关注公众号，则保存小程序openid信息
        if(openIdinfoPO==null && StringUtils.isNotEmpty(unionId) && !unionId.equals("null")){
            WeChatUserOpenIdInfoPO infoPO = new WeChatUserOpenIdInfoPO();
            infoPO.setUserOpenId(LogicIdUtil.bussinessId());
            infoPO.setMiniOpenId(openId);
            infoPO.setUnionId(unionId);
            infoPO.setUserId(userId);
            infoPO.setCreateTime(new Date());
            infoPO.setUpdateTime(new Date());
            infoPO.setStatus(DataStatusEnum.NORMAL.getType());
            iAppRegisterDao.save(SqlUtil.durableData(infoPO,PlatformConstants.TABLE_SAVE));
        }else{//当前用户提前关注公众号，则更新小程序Openid信息
            if(StringUtils.isNotEmpty(unionId) && !unionId.equals("null")){
                iAppRegisterDao.updateOpenIdByUnionId(openId,unionId,userId);
            }
        }
        //将信息存入缓存中
        appUserCacheVO.setPhoneNo(phoneNo);
        appUserCacheVO.setUserId(userId);
        appUserCacheVO.setMiniToken(token);

        redisService.set(RedisConstant.MINI_PROGRAM_LOGIN+appUserCacheVO.getUserId(),RedisConstant.APP_USER_TOKEN_TIME,appUserCacheVO);
        return appUserCacheVO;
    }

    /**
     * <desc>
     *      校验该用户是否被禁用
     * </desc>
     *
     * @param phoneNo  手机号
     * @return
     * @author Juguang.S
     * @createDate 2019/01/05
     */
    @Override
    public Integer getUserStatus(String phoneNo){
        return iAppRegisterDao.getUserStatus(phoneNo);
    }

    /**
     * <desc>
     *     退出登录
     * </desc>
     *
     * @param token
     * @return
     * @author Juguang.S
     * @createDate 2018/11/24
     */
    @Override
    @Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRED)
    public void loginOut(String token) throws Exception {
        String userId = UserTokenUtil.tokenDecrypt(token,MINI_PROGRAM_USER_TOKEN_KEY);
        AppUserCacheVO appUserCacheVO = redisService.getObject(RedisConstant.MINI_PROGRAM_LOGIN+userId,AppUserCacheVO.class);
        boolean redisflag = redisService.set(RedisConstant.MINI_PROGRAM_LOGIN + userId,RedisConstant.LOGIN_OUT_APP_USER_TOKEN_TIME,appUserCacheVO);
        if (!redisflag){
            LOG.info("【微信小程序_登录】登出清理缓存失败");
        }

        //当微信小程序增加云对讲功能后再将以下代码取消注释 并考虑app-user-info表中增加微信小程序用户是否在线字段与APP该字段进行区分
        /*AppUserInfoPO appUserInfoPO = new AppUserInfoPO(userId);
        appUserInfoPO.setIsOnline(0);
        boolean flag = iAppRegisterDao.updateByPoNotNull(appUserInfoPO)>0?true:false;
        if (flag){
            if (appUserCacheVO != null){
                List<AppUserOwnProjectVO> userOwnProjectList = appUserCacheVO.getProjects();
                if (userOwnProjectList != null&&userOwnProjectList.size()>0){
                    for (AppUserOwnProjectVO appUserOwnProjectVO:userOwnProjectList){
                        JSONObject js = new JSONObject();
                        js.put("projectId",appUserOwnProjectVO.getProjectId());
                        js.put("userId",appUserCacheVO.getUserId());
                        DeviceBusinessChangeLogPO deviceBusinessChangeLogPO = new DeviceBusinessChangeLogPO(SmartCommunityEnum.PUSH_USER_PROJECT,js,appUserOwnProjectVO.getProjectId());
                        List<DeviceBusinessChangeLogPO> changeLogPOS = new ArrayList<>();
                        changeLogPOS.add(deviceBusinessChangeLogPO);
                        if (changeLogPOS != null && !changeLogPOS.isEmpty()) {
                            JSONObject datajs = new JSONObject();
                            datajs.put("data",changeLogPOS);
                            messageSender.send(RabbitMQConstant.RABBITMQ_HANDLE_SMART_COMMUNITY_ORDERS_QUEUE,
                                    JSON.toJSONString(datajs), RabbitMQConstant.RABBITMQ_SMART_COMMUNITY_ORDERS_EXCHANGE,
                                    RabbitMQConstant.RABBITMQ_SMART_COMMUNITY_ORDERS_ROUTING_KEY);
                        }
                    }
                }
            }
        }*/

    }

    /**
     * <desc>
     *      从缓存获取用户信息
     * </desc>
     *
     * @param token
     * @return
     * @author Juguang.S
     * @createDate 2018/11/26
     */
    @Override
    public AppUserCacheVO retrieve(String token) {
        try {
            if (StringUtils.isBlank(token)) {
                return null;
            }
            //解密拿到userId
            String userId = UserTokenUtil.tokenDecrypt(token, MINI_PROGRAM_USER_TOKEN_KEY);
            if (userId == null) {
                return null;
            }

            AppUserCacheVO userInfo = redisService.getObject(RedisConstant.MINI_PROGRAM_LOGIN+userId, AppUserCacheVO.class);
            if (userInfo != null && token.equals(userInfo.getMiniToken())) {
                Integer userStatus = iAppRegisterService.getAppUserStatusByUserId(userId);
                if (userStatus == null){
                    userInfo.setStatus(1);
                }else {
                    userInfo.setStatus(userStatus);
                }
                return userInfo;
            } else {
                userInfo = this.resetUserLogin(userId);
                //LOG.info("【微信小程序-Token拦截成功】--userId:" + userId + "--" + DateUtil.getCurrentTime() + "--缓存不存在--备用查询用户");
                if (userInfo!=null && userInfo.getStatus() == null){
                    userInfo.setStatus(1);
                }
                if (userInfo == null){
                    //LOG.info("【微信小程序-Token拦截成功】--userId:" +userId+"--token:"+token+"--"+ DateUtil.getCurrentTime()+"--缓存不存在--备用查询用户不存在");
                }
                return userInfo;
            }
        }catch (RedisConnectionFailureException e){
            //LOG.error("【微信小程序-Token拦截成功】--"+ DateUtil.getCurrentTime()+"--微信小程序retrieve【从缓存中获取用户信息】redis连接失败");
            throw new DataAccessException("微信小程序retrieve【从缓存中获取用户信息】redis连接失败") ;
        }
    }

    /**
     * <desc>
     *     微信小程序用户缓存丢失后备用查询缓存用户
     * </desc>
     *
     * @param userId
     * @return
     * @author Juguang.S
     * @createDate 2018/11/26
     */
    @Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRED)
    public  AppUserCacheVO  resetUserLogin(String userId) {
        try {
            Date current = new Date();
            AppUserInfoPO userInfoPO = new AppUserInfoPO(userId);
            AppUserInfoPO appUserInfoPO = iAppRegisterDao.getOne(userInfoPO);
            if (appUserInfoPO == null){
                return  null;
            }else {
                if (DateUtil.daysOfTwo(appUserInfoPO.getUpdateTime(),current)>=7){
                    return null;
                }
                AppUserCacheVO appUserCacheVO = new AppUserCacheVO();
                appUserCacheVO.setId(appUserInfoPO.getId());
                appUserCacheVO.setLoginDevice(appUserInfoPO.getLoginDevice()+"");
                appUserCacheVO.setUserId(appUserInfoPO.getUserId());
                appUserCacheVO.setPhotoUrl(appUserInfoPO.getIcon());
                appUserCacheVO.setNickName(appUserInfoPO.getNickName());
                appUserCacheVO.setUserName(appUserInfoPO.getRealName());
                appUserCacheVO.setEmail(appUserInfoPO.getEmail());
                if (StringUtils.isNotBlank(appUserInfoPO.getEmail())){
                    appUserCacheVO.setPhoneNo(appUserInfoPO.getEmail());
                }else {
                    appUserCacheVO.setPhoneNo(appUserInfoPO.getPhoneNum());
                }
                appUserCacheVO.setToken(appUserInfoPO.getToken());
                appUserCacheVO.setSex(appUserInfoPO.getGender()+"");
                appUserCacheVO.setCurrentProjectId(appUserInfoPO.getCurrentProjectId());
                appUserCacheVO.setCurrentProjectName(appUserInfoPO.getCurrentProjectName());
                appUserCacheVO.setStatus(appUserInfoPO.getStatus());
                appUserCacheVO.setUuid(appUserInfoPO.getUuid());

                List<AppUserOwnProjectVO> userOwnProjectList = this.getUserOwnProjectsInfo(userId,"-1");
                appUserCacheVO.setProjects(userOwnProjectList);
                if (userOwnProjectList != null&&userOwnProjectList.size()>0){ //未申请房屋认证审核通过或者全部房间均被迁出
                    if (StringUtils.isBlank(appUserCacheVO.getCurrentProjectId())||StringUtils.isBlank(appUserCacheVO.getCurrentProjectName())){
                        appUserCacheVO.setCurrentProjectId(userOwnProjectList.get(0).getProjectId());
                        appUserCacheVO.setCurrentProjectName(userOwnProjectList.get(0).getProjectName());
                    }
                }else {
                    appUserCacheVO.setCurrentProjectId("");
                    appUserCacheVO.setCurrentProjectName("");
                }
                appUserCacheVO = (AppUserCacheVO) StringHandlerUtil.formatString(appUserCacheVO);
                boolean flag = redisService.set(RedisConstant.MINI_PROGRAM_LOGIN+appUserCacheVO.getUserId(),RedisConstant.APP_USER_TOKEN_TIME,appUserCacheVO);
                userInfoPO.setUpdateTime(current);
                iAppRegisterDao.updateByPoNotNull(userInfoPO);

                return  appUserCacheVO;
            }
        }catch (Exception e){
            LOG.error("【微信小程序用户缓存丢失后备用查询缓存用户】当前时间：" + DateUtil.format(Calendar.getInstance(), "yyyy-MM-dd HH:mm:ss:"),e);
        }
        return null;
    }

    /**
     * <desc>
     *     微信小程序登录后缓存用户信息
     * </desc>
     * @param appUserCacheVO
     * @return
     * @author Juguang.S
     * @createDate 2018/11/26
     */
    @Override
    public boolean loginCacheUserVO(AppUserCacheVO appUserCacheVO) throws Exception{
        boolean flag = redisService.set(RedisConstant.MINI_PROGRAM_LOGIN+appUserCacheVO.getUserId(),RedisConstant.APP_USER_TOKEN_TIME,appUserCacheVO);
        if (flag){
            AppUserInfoPO appUserInfoPO = new AppUserInfoPO(appUserCacheVO.getUserId());
            //appUserInfoPO.setUuid(appUserCacheVO.getUuid());
            appUserInfoPO.setUpdateTime(new Date());
            appUserInfoPO.setMiniToken(appUserCacheVO.getToken());
            appUserInfoPO.setIsOnline(1);
            iAppRegisterDao.updateByPoNotNull(appUserInfoPO);
            //当微信小程序增加云对讲功能后再将以下代码取消注释 并考虑app-user-info表中增加微信小程序用户是否在线字段与APP该字段进行区分
            /*List<AppUserOwnProjectVO> userOwnProjectList = appUserCacheVO.getProjects();
            if (userOwnProjectList != null&&userOwnProjectList.size()>0){
                for (AppUserOwnProjectVO appUserOwnProjectVO:userOwnProjectList){
                    JSONObject js = new JSONObject();
                    js.put("projectId",appUserOwnProjectVO.getProjectId());
                    js.put("userId",appUserCacheVO.getUserId());
                    DeviceBusinessChangeLogPO deviceBusinessChangeLogPO = new DeviceBusinessChangeLogPO(SmartCommunityEnum.PUSH_USER_PROJECT,js,appUserOwnProjectVO.getProjectId());
                    List<DeviceBusinessChangeLogPO> changeLogPOS = new ArrayList<>();
                    changeLogPOS.add(deviceBusinessChangeLogPO);
                    if (changeLogPOS != null && !changeLogPOS.isEmpty()) {
                        JSONObject datajs = new JSONObject();
                        datajs.put("data",changeLogPOS);
                        messageSender.send(RabbitMQConstant.RABBITMQ_HANDLE_SMART_COMMUNITY_ORDERS_QUEUE,
                                JSON.toJSONString(datajs), RabbitMQConstant.RABBITMQ_SMART_COMMUNITY_ORDERS_EXCHANGE,
                                RabbitMQConstant.RABBITMQ_SMART_COMMUNITY_ORDERS_ROUTING_KEY);
                    }
                }
            }*/
        }
        return  flag;

    }

    /**
     * <desc>
     *     微信小程序端登录获取用户项目列表信息
     * </desc>
     *
     * @param userId  用户ID
     * @param deviceType 设备类型 1-安卓系统，2-ios系统
     * @return  APP用户所拥有的项目配置信息的集合
     * @throws Exception
     * @createDate 2017/9/27
     */
    @Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRED)
    public List<AppUserOwnProjectVO> getUserOwnProjectsInfo(String userId,String deviceType) throws  Exception{

        List<AppUserOwnProjectVO> userOwnProjectVOList = iAppRegisterDao.getUserOwnProjectsInfo(userId);
        List<AppUserOwnProjectVO> delUserOwnProjectVOList = new ArrayList<>();  //待移除的用户名下项目集合
        Map<String,Object> userprojectmap = new HashMap<>();
        userprojectmap.put("userId",userId);

        boolean isEmailUser = false;
        if (StringUtils.isNotBlank(iAppRegisterDao.getAppUserEmail(userId))){
            isEmailUser = true;//非空则为国际用户
        }

        if (userOwnProjectVOList != null&&userOwnProjectVOList.size()>0){
            Map<String,Object> params = new  HashMap<>();
            params.put("userId",userId);
            for (AppUserOwnProjectVO appUserOwnProjectVO:userOwnProjectVOList){
                params.put("projectId",appUserOwnProjectVO.getProjectId());
                Integer userAuthCount = iAppRegisterDao.countUserAttacheInfoInProject(params);
                appUserOwnProjectVO.setOwnerAddress(userAuthCount>0?"1":"0");
                params.put("houserType","1");  //业主身份
                Integer userAddressCount = iAppRegisterDao.countUserAttacheInfoInProject(params);
                appUserOwnProjectVO.setUserAuth(userAddressCount>0?"1":"0");
                //用户项目是否被禁用信息
                if(iAppRegisterDao.checkUserProjectStatus(appUserOwnProjectVO.getProjectId()) > 0){
                    appUserOwnProjectVO.setProjectMessage(
                            String.format(AppErrorCodeEnum.USER_PROJECT_DISABLED.getCodeMsg(), appUserOwnProjectVO.getProjectName(),appUserOwnProjectVO.getCenterPhoneNo() != null ? appUserOwnProjectVO.getCenterPhoneNo() : ""));
                    if (isEmailUser){ //国际版提示
                        appUserOwnProjectVO.setProjectMessage(
                                String.format(AppErrorCodeEnumEN.USER_PROJECT_DISABLED.getCodeMsg(), appUserOwnProjectVO.getCenterPhoneNo() != null ? appUserOwnProjectVO.getCenterPhoneNo() : ""));
                    }
                }else {
                    // 用户项目冻结提示信息
                    appUserOwnProjectVO.setProjectMessage(
                            appUserOwnProjectVO.getProjectMessage().equals("0") ?
                                    String.format(AppErrorCodeEnum.USER_PROJECT_FREEZE.getCodeMsg(),
                                            appUserOwnProjectVO.getProjectName(),
                                            appUserOwnProjectVO.getCenterPhoneNo() != null ? appUserOwnProjectVO.getCenterPhoneNo() : "") : ""
                    );
                    if (isEmailUser){ //国际版提示
                        appUserOwnProjectVO.setProjectMessage(
                                appUserOwnProjectVO.getProjectMessage().equals("0") ?
                                        String.format(AppErrorCodeEnumEN.USER_PROJECT_FREEZE.getCodeMsg(), appUserOwnProjectVO.getCenterPhoneNo() != null ? appUserOwnProjectVO.getCenterPhoneNo() : "") : "");
                    }
                }
                appUserOwnProjectVO = (AppUserOwnProjectVO)StringHandlerUtil.formatString(appUserOwnProjectVO);

                //用户在项目上无迁入状态的房间且无有效的用户-设备权限记录，则此项目不做展示
                userprojectmap.put("projectId",appUserOwnProjectVO.getProjectId());
                Integer userInProjectExistRoom = iAppRegisterDao.countUserRoomInProject(userprojectmap);
                if (!(userInProjectExistRoom != null&&userInProjectExistRoom > 0)){
                    Integer countUserAuthInFloor = iAppRegisterDao.countUserAuthInFloor(userprojectmap);
                    Integer countUserAuthInDoor = iAppRegisterDao.countUserAuthInDoor(userprojectmap);
                    Integer countUserAuthInCloudDoor = iAppRegisterDao.countUserAuthInCloudDoor(userprojectmap);
                    if (!((countUserAuthInFloor+countUserAuthInDoor+countUserAuthInCloudDoor)>0)){
                        delUserOwnProjectVOList.add(appUserOwnProjectVO);
                    }
                }
            }
        }
        if (delUserOwnProjectVOList != null&&delUserOwnProjectVOList.size()>0){
            userOwnProjectVOList.removeAll(delUserOwnProjectVOList);
        }

        //获取用户有效项目的UI状态
        if((StringUtils.isNotBlank(deviceType)&&("1".equals(deviceType)||"2".equals(deviceType)))&&((userOwnProjectVOList!=null)&&(userOwnProjectVOList.size()>0))){
            String type = "1".equals(deviceType)?"2":"1"; //UI类型中 1是ios 2是安卓所以需要转换
            userOwnProjectVOList.forEach(ownProjectInfo->{
                String tmp = iAppRegisterDao.getUiStatus(ownProjectInfo.getProjectId(),type);
                if(StringUtils.isBlank(tmp) || (!"1".equals(tmp))){
                    ownProjectInfo.setUiStatus("0");
                }else {
                    ownProjectInfo.setUiStatus("1");
                }
            });
        }
        return  userOwnProjectVOList;
    }

    /**
     * <desc>
     *      从缓存获取用户信息 用于校验token是否过期
     * </desc>
     *
     * @param token
     * @return
     * @author Juguang.S
     * @createDate 2020/03/10
     */
    @Override
    public AppUserCacheVO retrieveByCheckToken(String token) {
        try {
            if (StringUtils.isBlank(token)) {
                return null;
            }
            //解密拿到userId
            String userId = UserTokenUtil.tokenDecrypt(token, MINI_PROGRAM_USER_TOKEN_KEY);
            if (userId == null) {
                return null;
            }

            AppUserCacheVO userInfo = redisService.getObject(RedisConstant.MINI_PROGRAM_LOGIN+userId, AppUserCacheVO.class);
            if (userInfo != null && token.equals(userInfo.getMiniToken())) {
                Integer userStatus = iAppRegisterService.getAppUserStatusByUserId(userId);
                if (userStatus == null){
                    userInfo.setStatus(1);
                }else {
                    userInfo.setStatus(userStatus);
                }
                redisService.set(RedisConstant.MINI_PROGRAM_LOGIN+userInfo.getUserId(),RedisConstant.APP_USER_TOKEN_TIME,userInfo);
            }
            return userInfo;
        }catch (RedisConnectionFailureException e){
            LOG.error("【微信小程序-Token拦截成功】--"+ DateUtil.getCurrentTime()+"--微信小程序retrieve【从缓存中获取用户信息】redis连接失败");
            throw new DataAccessException("微信小程序retrieve【从缓存中获取用户信息】redis连接失败") ;
        }
    }
}